package com.lightsaber.cut.func;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Solutions {

    private List<Point> solutionAll = new ArrayList<Point>();

    /**
     * 纯碎线性分析得出的理想方案
     */
    private List<Point> solutionOfLineAnalyze = new ArrayList<Point>();

    /**
     * 在线性分析 和 实际切割极限的基础上, 舍弃部分尺寸得出的方案
     */
    private List<Point> solutionOfGiveUp = new ArrayList<Point>();

    public void solutionOfLineAnalyzeAdd(Point point) {
        solutionAll.add(point);
        solutionOfLineAnalyze.add(point);
    }

    public void solutionOfGiveUpAdd(Point point) {
        solutionAll.add(point);
        solutionOfGiveUp.add(point);
    }

    public List<Point> getSolutionAll() {
        return solutionAll;
    }

    public List<Point> getSolutionOfLineAnalyze() {
        return solutionOfLineAnalyze;
    }

    public List<Point> getSolutionOfGiveUp() {
        return solutionOfGiveUp;
    }

    public Map<String, Point> mapping() {
        Map<String, Point> pointMap = new HashMap<String, Point>();
        for (Point p : solutionAll) {
            pointMap.put(p.getX() + "-" + p.getY(), p);
        }

        return pointMap;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("----------------------------------------------------------------------\r\n");
        sb.append("满足'线性分析' 和 '切割极限' 条件的方案:\r\n");

        for (Point p : solutionAll) {
            sb.append(p.toStringXY() + ", ");
        }

        sb.append("\r\n其中满足'线性分析'条件的方案:\r\n");

        for (Point p : solutionOfLineAnalyze) {
            sb.append(p.toStringXY() + ", ");
        }

        return sb.toString();
    }

    /**
     * 实际能切割的点
     * 
     * @return
     */
    public String toStringExperiment() {
        StringBuilder sb = new StringBuilder();
        sb.append("----------------------------------------------------------------------\r\n");
        sb.append("满足'线性分析' 和 '切割极限' 条件的方案, 且实验可行的点:\r\n");

        for (Point p : solutionAll) {
            if (p.getOriginals() != null) {
                sb.append(p.toStringXY() + ", ");
            }
        }

        sb.append("\r\n其中满足'线性分析'条件的方案, 且实验可行的点:\r\n");

        for (Point p : solutionOfLineAnalyze) {
            if (p.getOriginals() != null) {
                sb.append(p.toStringXY() + ", ");
            }
        }

        return sb.toString();
    }
}
